<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>文件管理</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
        <link rel="stylesheet" href="${ctx}/layui/css/layui.css" media="all"/>
        <link rel="stylesheet" href="${ctx}/systemStatic/style/admin.css">
        <link rel="stylesheet" href="${ctx}/extends/zTree_v3/css/zTreeStyle/zTreeStyle.css"/>
        <link rel="stylesheet" href="${ctx}/iconfont/iconfont.css"/>
        <link rel="stylesheet" href="${ctx}/css/public.css">
        <script type="text/javascript">
            var __ctx = "${ctx}";
        </script>
        <style>
            #rMenu{visibility:hidden;position: absolute;padding: 0 6px;background: #f5f5f5;border: 1px solid #ccc}
            #rMenu li{padding: 6px;cursor: pointer;text-align: left}
        </style>
    </head>
    <body>
        <div style="position: relative;height: 100%;">
            <div class="ccpui-trees">
                <p class="isShowTree colorSwitch">
                    <span style="float: left;color: #fff">&nbsp;&nbsp;文件结构树</span>
                    <i layadmin-event="treeFlexible" class="layui-icon layui-icon-prev"></i>
                </p>
                <div style="margin-top: 6px;">
                    <ul class="ccpui-iconTree iconTrees">
                        <li><a class="iconfont iconshuaxin-" fileManage-event="zTreeRefresh" title="刷新"></a></li>
                        <li><a class="iconfont iconwenjianjia1-copy" fileManage-event="zTreeshow" title="展开"></a></li>
                        <li><a class="iconfont iconfolder1" fileManage-event="zTreeClose" title="收起"></a></li>
                        <li><a class="iconfont iconplus-circle" title="添加根节点" fileManage-event="addRoot"></a></li>
                        <li><a class="iconfont iconrank" title="切换到逻辑树" treeType="1" fileManage-event="toggleTree"></a></li>
                        <input type="text" style="width: 94%" class="fileZtreeValue">
                    </ul>
                    <ul id="treeSelectRoles" class="ztree ccpui-listZtree" style="top:94px"></ul>
                </div>
            </div>
            <div class="ccpui-coreContent">
                <table id="fileManagementList" lay-filter="fileManagementList"></table>
            </div>
        </div>
        <!-- 头部工具栏 -->
        <script type="text/html" id="headerToolsBarRole">
            <div class="ccpui-enterSel">
                <div class="layui-btn-container fileheadertool">
                    <a class="layui-btn layui-btn-sm" lay-event="query">
                        <i class="layui-icon">&#xe615;</i>
                        <span>查询</span>
                    </a>
                    <a class="layui-btn layui-btn-sm" lay-event="clears">
                        <i class="layui-icon">&#xe9aa;</i>
                        <span>重置</span>
                    </a>
                    <#if parentType =='1'>
                    <a class="layui-btn layui-btn-sm" lay-event="delete">
                        <i class="layui-icon">&#xe640;</i>
                        <span>删除</span>
                    </a>
                </#if>
                <#if managePermission.addFolder==true>
                <a class="layui-btn layui-btn-sm" lay-event="add">
                    <i class="layui-icon layui-icon-add-1"></i> <span>新建文件夹</span>
                </a>
            </#if>
            <#if managePermission.addMapping==true>
            <a class="layui-btn layui-btn-sm" lay-event="fileMapping">
                <i class="layui-icon layui-icon-engine"></i> <span>文件映射</span>
            </a>
            </#if>
            <#if managePermission.addFile==true>
            <a class="layui-btn layui-btn-sm" lay-event="fileUpload">
                <i class="layui-icon layui-icon-upload-drag"></i> <span>上传文件</span>
            </a>
            </#if>
            <#if managePermission.download==true>
            <a class="layui-btn layui-btn-sm" lay-event="topdownloadFiles">
                <i class="layui-icon layui-icon-download-circle"></i> <span>下载</span>
            </a>
            </#if>
            </div>
            <form class="layui-form" action="" lay-filter="fileSelect" style="margin-top:10px">
                <div class="table-top-filter">
                    <div class="table-filter-alone">
                        <label class="layui-form-label">文件名称</label>
                        <input type="text" class="layui-input  filter-value" name="Q_fileName_SL"/>
                    </div>
                    <div class="table-filter-alone">
                        <label class="layui-form-label">摘要</label>
                        <input type="text" class="layui-input  filter-value" name="Q_fileKeywords_SL"/>
                    </div>
                </div>
            </form>
            </div>
        </script>
        <script type="text/html" id="headerToolsBarRoleLogicTree">
            <div class="ccpui-enterSel">
                <div class="layui-btn-container fileheadertool">
                    <a class="layui-btn layui-btn-sm" lay-event="query">
                        <i class="layui-icon">&#xe615;</i>
                        <span>查询</span>
                    </a>
                    <a class="layui-btn layui-btn-sm" lay-event="clears">
                        <i class="layui-icon">&#xe9aa;</i>
                        <span>重置</span>
                    </a>
                    <#if managePermission.addFolder==true>
                    <a class="layui-btn layui-btn-sm" lay-event="add">
                        <i class="layui-icon layui-icon-add-1"></i> <span>新建文件夹</span>
                    </a>
                </#if>
                <#if managePermission.cancelMapping==true>
                <a class="layui-btn layui-btn-sm" lay-event="canfileMapping">
                    <i class="layui-icon layui-icon-fonts-del"></i> <span>取消文件映射</span>
                </a>
            </#if>
            <#if managePermission.download==true>
            <a class="layui-btn layui-btn-sm" lay-event="topdownloadFiles">
                <i class="layui-icon layui-icon-download-circle"></i> <span>下载</span>
            </a>
            </#if>
            </div>
            <form class="layui-form" action="" lay-filter="fileSelect" style="margin-top:10px">
                <div class="table-top-filter">
                    <div class="table-filter-alone">
                        <label class="layui-form-label">文件名称</label>
                        <input type="text" class="layui-input  filter-value" name="Q_fileName_SL"/>
                    </div>
                    <div class="table-filter-alone">
                        <label class="layui-form-label">摘要</label>
                        <input type="text" class="layui-input  filter-value" name="Q_fileKeywords_SL"/>
                    </div>
                </div>
            </form>
            </div>
        </script>
        <!--右键菜单-->
        <div id="rMenu">
            <ul>
                <#if managePermission.addFolder==true>
                <li fileManage-event="addFolder">新建文件夹</li>
            </#if>
            <#if managePermission.addFile==true&&parentType=='1'>
            <li fileManage-event="addFiles">上传</li>
        </#if>
        <#if managePermission.download==true>
        <li fileManage-event="downloadFiles">下载</li>
    </#if>
    <li fileManage-event="delFiles">删除</li>
    <#if managePermission.edit==true>
    <li fileManage-event="editFile">编辑</li>
</#if>
<#if managePermission.addToResource==true>
<li fileManage-event="addToMenu">添加为菜单</li>
</#if>
</ul>
</div>

<!--添加根节点-->
<div class="fileManagement-addRoot">
    <div class="layui-form">
        <div class="layui-form-item" style="margin-top: 15px">
            <label class="layui-form-label">根节点</label>
            <div class="layui-input-block">
                <input type="radio" name="parentType" class="radioNodesel" value="1" title="物理树目录节点 " checked="checked">
                <input type="radio" name="parentType" value="2" title="归类逻辑树目录节点">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">文件夹名称</label>
            <div class="layui-input-inline" style="width: 310px">
                <input type="text" name="fileName" maxlength="80" lay-verify="required"  autocomplete="off"  class="layui-input rootfileName">
            </div>
        </div>
        <div class="layui-form-item layui-hide">
            <input type="button" lay-submit lay-filter="addRootid-submit" id="addRootidSubmit">
        </div>
    </div>
</div>
<!--新建文件夹-->
<div class="fileManagement-addFolder">
    <div class="layui-form" id="addFolderid" lay-filter="addFolderid">
        <div class="layui-form-item" style="margin-top: 15px">
            <label class="layui-form-label">父节点</label>
            <div class="layui-input-block">
                <span class="parentNamecont" style="line-height: 38px"></span>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">文件夹名称</label>
            <div class="layui-input-inline" style="width: 310px">
                <input type="text" name="fileName" maxlength="80" lay-verify="required" autocomplete="off"  class="layui-input addfolderfileName">
            </div>
        </div>
        <div class="layui-form-item layui-hide">
            <input type="button" lay-submit lay-filter="addFolder-submit" id="addFolderSubmit">
        </div>
    </div>
</div>

<!--编辑功能-->
<div class="fileManagement-editFolder">
    <div class="layui-form">
        <div class="layui-form-item" style="margin-top: 15px">
            <label class="layui-form-label">文件夹名称</label>
            <div class="layui-input-inline" style="width: 310px">
                <input type="text" name="fileName" maxlength="80" lay-verify="required" autocomplete="off"  class="layui-input editfolderfileName">
            </div>
        </div>
        <div class="layui-form-item layui-hide">
            <input type="button" lay-submit lay-filter="editFolder-submit" id="editFolderSubmit">
        </div>
    </div>
</div>

<!-- 右侧工具栏 -->
<script type="text/html" id="rightToolsBarRole"></script>
<script src="${ctx}/extends/jquery.min.js" type="text/javascript"></script>
<script src="${ctx}/public/component.js" type="text/javascript"></script>
<script src="${ctx}/layui/layui.js"></script>
<script src="${ctx}/extends/zTree_v3/js/jquery.ztree.all.min.js" type="text/javascript"></script>
<script src="${ctx}/extends/zTree_v3/js/jquery.ztree.exhide.min.js" type="text/javascript"></script>
<script>
    layui.config({
        base: serverPath.systemPath + staticPath.systemPath //静态资源所在路径
    }).extend({
        index: 'index' //主入口模块
    }).use(['index', 'setter', 'commons', 'form', 'jquery', 'layer', 'common', 'table', 'totalFilter'], function () {
        var table = layui.table, layer = layui.layer, setter = layui.setter, commons = layui.commons,
            common = layui.common, totalFilter = layui.totalFilter, form = layui.form, $ = layui.jquery;

        var globalVriable={//全局变量集合
            parentType:'1' //初始化treetype参数  1物理树目录节点 2逻辑归类树目录节点
            ,nowTreeNodeid:'' //当前单击树节点id
            ,nowTreeNodeinfo : ''//当前节点信息
            ,nowRightTreeNodeid:'' //当前右键树节点id
            ,nowRightTreeNodeinfo : ''//当前右键节点信息
        };

        fileZtree({treeType:'1'});//初始化树
        function fileZtree(datajson) {
            $.ajax({
                url: serverPath.systemPath + setter.sysLinkPath + "fileManagement/list",
                type: "get",
                contentType: 'application/json',
                dataType: 'json',
                async:false,
                data:datajson,
                success: function (data) {
                    var zNodes = data.data.treeList;
                    var setting = {
                        data: {
                            simpleData: {
                                enable: true,
                            }
                        },
                        callback: {
                            onClick: onClickRoles,
                            onRightClick: OnRightClick
                        }
                    };
                    $.fn.zTree.init($('#treeSelectRoles'), setting, zNodes);
                    getrightMenu(data.data.managePermission);//初始化右键菜单
                    component.fuzzySearch('treeSelectRoles', '.fileZtreeValue', null, true); //初始化模糊搜索方法
                    var treeNode = $.fn.zTree.getZTreeObj("treeSelectRoles");
                    var firstNode = treeNode.getNodes()[0];
                    if (firstNode&&firstNode != null) {
                        treeNode.selectNode(firstNode);
                        globalVriable.nowTreeNodeid = firstNode.id;
                        globalVriable.nowTreeNodeinfo = firstNode;//当前节点信息
                        toggleTable({parentType:globalVriable.parentType,"parentId": firstNode.id});//初始化表
                    }else{
                        toggleTable({parentType:globalVriable.parentType});//初始化表
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    layer.alert("暂无数据，请稍后操作！" + XMLHttpRequest.status);
                },
            });
        }

        function onClickRoles(event, treeId, treeNode, clickFlag) {
            globalVriable.nowTreeNodeid = treeNode.id;
            globalVriable.nowTreeNodeinfo = treeNode;//当前节点信息
            var info = {
                Id:treeNode.id,
                info:treeNode
            };
            localStorage.setItem('nowTreeNodeinfos', JSON.stringify(info));
            common.tableConditionRender("fileManagementList", "fileSelect", {where: {"parentId": treeNode.id,parentType:globalVriable.parentType}}, true);
        }
        function OnRightClick(event, treeId, treeNode) {
            if (treeNode && !treeNode.noR) {
                globalVriable.nowRightTreeNodeid = treeNode.id;
                globalVriable.nowRightTreeNodeinfo = treeNode;//当前节点信息
                showRMenu( event.clientX, event.clientY);
            }
            if(treeNode!==null){
                var info = {
                    parentId:treeNode.id,
                    parentType:treeNode.parentType
                };
                localStorage.setItem('infos', JSON.stringify(info));
            }
        }
        function showRMenu( x, y) {
            $("#rMenu ul").show();

            y += document.body.scrollTop;
            x += document.body.scrollLeft;
            $("#rMenu").css({"top":y+"px", "left":x+"px", "visibility":"visible"});

            $("body").bind("mousedown", onBodyMouseDown);
        }
        function hideRMenu() {
            if ($("#rMenu")) $("#rMenu").css({"visibility": "hidden"});
            $("body").unbind("mousedown", onBodyMouseDown);
        }
        function onBodyMouseDown(event){
            if (!(event.target.id == "rMenu" || $(event.target).parents("#rMenu").length>0)) {
                $("#rMenu").css({"visibility" : "hidden"});
            }
        }

        //右键菜单
        function getrightMenu(data) {
            //没有任何按钮权限时候 不显示右键菜单
            if($('#rMenu ul').children().length<1){
                $("#rMenu").css({"visibility": "hidden"});
            }
        }

        //列表右侧按钮权限
        function btnmanagePermission(data) {
            $('#rightToolsBarRole').html('');
            if(data&&data.edit){
                $('#rightToolsBarRole').append(' <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>')
            }
            if(globalVriable.parentType=='1'){
                $('#rightToolsBarRole').append('<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>')
            }
            if(data&&data.download){
                $('#rightToolsBarRole').append('<a class="layui-btn layui-btn-xs" lay-event="downloadfile">下载</a>')
            }
        }

        //判断文件类型  选择图标
        function fileTypeIcon(val) {
            var html='';
            switch (val) {
                case 'docx':
                    html='<img src="${ctx}/systemStatic/images/docx.gif" width="18px">';
                    break;
                case 'doc':
                    html='<img src="${ctx}/systemStatic/images/docx.gif" width="18px">';
                    break;
                case 'mp3':
                    html='<img src="${ctx}/systemStatic/images/mp3.gif" width="18px">';
                    break;
                case 'mp4':
                    html='<img src="${ctx}/systemStatic/images/mp4.gif" width="18px">';
                    break;
                case 'photo':
                    html='<img src="${ctx}/systemStatic/images/photo.gif" width="18px">';
                    break;
                case 'ppt':
                    html='<img src="${ctx}/systemStatic/images/ppt.gif" width="18px">';
                    break;
                case 'xls':
                    html='<img src="${ctx}/systemStatic/images/xls.gif" width="18px">';
                    break;
                case 'xlsx':
                    html='<img src="${ctx}/systemStatic/images/xls.gif" width="18px">';
                    break;
                case 'zip':
                    html='<img src="${ctx}/systemStatic/images/zip.gif" width="18px">';
                    break;
                case 'txt':
                    html='<img src="${ctx}/systemStatic/images/txt.gif" width="18px">';
                    break;
                default:
                    html='<img src="${ctx}/systemStatic/images/unKnow.gif" width="18px">';
            }
            return html;
        }

        function toggleTable(datajson){
            var returnbtnData='';//按钮权限
            var filePermission='';//目录授权权限
            var tableCols=[{type: 'checkbox'},
                {field: 'id', title: 'ID', sort: true, hide: true},
                {field: 'fileName',event: 'fileName', align: "center", title: '文件名称', sort: true,sortname:'file_name',
                    templet: function (d) {
                        if(d.fileType=='1'){
                            var fileNameA = "<span style='cursor: pointer; color: #0b73df;'>"+d.fileName+"</span>"
                            return fileNameA
                        }
                        var imghtml=fileTypeIcon(d.fileFormat);
                        return imghtml+' '+d.fileName+'.'+d.fileFormat;
                    }},
                {field: 'fileSecretLevel', align: "center", title: '文件密级',sort: true,sortname:'file_secret_level',templet: function (d) {return d.fileSecretStr;}},
                {field: 'fileKeywords', title: '摘要', align: "center",sort: true,sortname:'file_keywords'},
                {field: 'fileSize', align: "center", title: '大小', sort: true,sortname:'totalBytes'},
                {field: 'uploadPersonName', align: "center", title: '上传人', sort: true,sortname:'upload_person_name'},
                {field: 'uploadDate', align: "center", title: '上传时间',templet: function(d) {return component.timeData(d.uploadDate);}, sort: true,sortname:'upload_date'},
                {align: 'center', title: '管理', toolbar: '#rightToolsBarRole'}
            ];
            if(datajson&&datajson.parentType==2){
                tableCols.splice(3, 0, {field: 'alias', align: "center", title: '映射文件别名', sort: true});
                tableCols.splice(9, 0, {field: 'orderNumber', align: "center", title: '排序编号',sortname:'order_number'});
            }
            var toolsBar ="#headerToolsBarRole";
            if(datajson.parentType==2){
                toolsBar ="#headerToolsBarRoleLogicTree";
            }
            table.render({
                elem: '#fileManagementList',
                cellMinWidth: 80,
                title: '文件信息列表',
                autoSort: false,
                height: commons.tabHeight(),
                defaultToolbar: ['filter', 'print'],
                url: serverPath.systemPath + setter.sysLinkPath + "fileManagement/fileManagementList",
                page: true,
                method: 'get',
                where:datajson,
                toolbar: toolsBar,
                cols:[tableCols],
                parseData: function(res){ //res 即为原始返回的数据
                    btnmanagePermission(res.data.managePermission);
                    returnbtnData=res.data.managePermission;
                    filePermission=res.data.nodePermission;
                    return {
                        "code": res.code, //解析接口状态
                        "msg": res.msg, //解析提示文本
                        "count": res.count, //解析数据长度
                        "data": res.data.fileManagementList //解析数据列表
                    };
                }
                ,done: function () {
                    if(filePermission && !$('.layui-btn-container.fileheadertool').hasClass("nodePermission")){//目录授权
                        $('.layui-btn-container.fileheadertool').append('<a class="layui-btn layui-btn-sm nodePermission" lay-event="nodePermission">' +
                            '<i class="layui-icon layui-icon-template"></i><span>目录授权</span></a>')
                        table.resize('fileManagementList');
                    }
                    common.tableSelectCon('.ccpui-enterSel .layui-form input', 'a[lay-event=query]', '.ccpui-enterSel');
                }
            });
        }

        totalFilter.init('fileManagementList');
        //监听头工具栏事件
        table.on('toolbar(fileManagementList)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            var objData = checkStatus.data;
            switch (obj.event) {
                case 'add':
                    var treeNodes = $.fn.zTree.getZTreeObj("treeSelectRoles");
                    var nodes = treeNodes.getNodes();
                    if(nodes&&nodes.length>0){
                        events.addFolder('1')
                    }else{
                        events.addRoot()
                    }
                    break;
                case 'delete':
                    if (objData.length === 0) {
                        layer.msg('请先选择一行数据！');
                    } else {
                        layer.confirm('确定删除当前数据吗？', function () {
                            var seleIds = [];
                            for (var i = 0; i < objData.length; i++) {
                                seleIds.push(objData[i].id);
                            }
                            $.ajax({
                                url: serverPath.systemPath + setter.sysLinkPath + "fileManagement/deleteFile",
                                type: "post",
                                dataType: 'json',
                                data: {fileIds: seleIds.join(",")},
                                success: function (res) {
                                    layer.alert(res.msg);
                                    if(res.code=='0'){
                                        table.reload('fileManagementList', {
                                            page: {curr: 1, limit: 10},
                                        });
                                        totalFilter.init('fileManagementList');
                                        var treeNodeNow= $.fn.zTree.getZTreeObj("treeSelectRoles");
                                        var delNodeInfo='';
                                        for(var i=0;i<seleIds.length;i++){
                                            delNodeInfo=treeNodeNow.getNodesByParam("id",seleIds[i])[0];
                                            treeNodeNow.removeNode(delNodeInfo);
                                            if(seleIds[i] ==globalVriable.nowTreeNodeid){
                                                globalVriable.nowTreeNodeinfo='';
                                                globalVriable.nowTreeNodeid='';
                                            }
                                        }
                                    }
                                }
                            })
                        })
                    }
                    break;
                case 'query':
                    common.tableConditionRender("fileManagementList", "fileSelect", {where: {}}, false);
                    break;
                case 'clears':
                    common.tableConditionRender("fileManagementList", "fileSelect", {where: {}}, true);
                    break;
                case 'nodePermission':
                    if(globalVriable.nowTreeNodeid){
                        layer.open({
                            type: 2,
                            area: ['1000px', '420px'],
                            title: ['目录授权'],
                            content: serverPath.systemPath + setter.sysLinkPath + 'fileManagementPermission/view/nodePermission?nodeId=' + globalVriable.nowTreeNodeid + '&permissionType=2'
                        });
                    }else {
                        layer.alert("请选中一个节点！");
                    }

                    break;
                case 'fileMapping':
                    if (objData.length === 0) {
                        layer.msg('请选择文件！',{icon: 0});
                    } else {
                        var body;
                        var userSelectorWin;
                        var theFileIds = [];
                        var isFile = true;
                        $.each(objData,function (key,val) {
                            if (val.fileType!==2){
                                isFile = false;
                            }else {
                                theFileIds.push(val.id)
                            }
                        })
                        if (isFile){
                            layer.open({
                                type: 2,
                                area: ['400px', '500px'],
                                btn:['保存','取消'],
                                title: ['文件映射'],
                                content: serverPath.systemPath + setter.sysLinkPath + 'fileManagement/view/mapping',
                                success: function(layero, index){
                                    body = layer.getChildFrame('body',index);
                                    userSelectorWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                                },
                                yes:function (index, layero) {
                                    if(body.find("input[name=treeLj]").val()!==""){
                                        var dataMapping = {
                                            fileIds:theFileIds.toString(),
                                            alias:objData[0].fileName,
                                            parentId: body.find("input[name=treeLj]").val()
                                        }
                                        $.ajax({
                                            url:serverPath.systemPath + setter.sysLinkPath + "fileManagement/addMapping",
                                            type: "post",
                                            dataType: 'json',
                                            data:dataMapping,
                                            success: function (res) {
                                                if (res.code==0){
                                                    if(res.data==""){
                                                        layer.close(index); //再执行关闭
                                                        layer.msg(res.msg,{icon: 6});
                                                    }else {
                                                        layer.msg(res.data,{icon: 0});
                                                    }

                                                }
                                            }
                                        });
                                    }else {
                                        layer.msg('请选择目录！',{icon: 0});
                                    }
                                },
                                btn2:function (index, layero) {
                                    layer.close(index); //再执行关闭
                                }
                            });
                        }else {
                            layer.msg("不能选择文件夹！",{icon: 0});
                        }
                    }
                    break;
                case 'fileUpload':
                    events.addFiles('1');
                    break;
                case 'topdownloadFiles':
                    if (objData.length === 0) {
                        layer.msg('请先选择一行数据！');
                    } else {
                        layer.confirm('确定下载选中文件吗？', function (index) {
                            layer.close(index);
                            var seleIds = [];
                            for (var i = 0; i < objData.length; i++) {
                                seleIds.push(objData[i].id);
                            }
                            var url = serverPath.systemPath + setter.sysLinkPath + 'fileManagement/downloadFile?fileIds='+ seleIds.join(",");
                            window.location.href = url;
                        })
                    }
                    break
                case 'canfileMapping':
                    if (objData.length === 0) {
                        layer.msg('请先选择一行数据！',{icon: 0});
                    } else {
                        var theFileIds = [];
                        var isFile = true;
                        $.each(objData,function (key,val) {
                            if (val.fileType!==2){
                                isFile = false;
                            }else {
                                theFileIds.push(val.id)
                            }
                        })
                        if(isFile){
                            layer.confirm('确认取消映射吗?',{icon: 3, title:'提示'}, function(index){
                                //do something
                                $.ajax({
                                    url:serverPath.systemPath + setter.sysLinkPath + "fileManagement/cancelMapping",
                                    type: "post",
                                    dataType: 'json',
                                    data:{fileIds:theFileIds.toString()},
                                    success: function (res) {
                                        if (res.code==0){
                                            layer.close(index); //再执行关闭
                                            table.reload('fileManagementList');
                                            layer.msg(res.msg,{icon: 6});
                                        }
                                    }
                                });
                            });
                        }else {
                            layer.msg('请选择文件！',{icon: 0});
                        }
                    }
                    break
            }
        });

        //监听行工具事件
        table.on('tool(fileManagementList)', function (obj) {
            var data = obj.data;
            switch (obj.event) {
                case 'del':
                    layer.confirm('确定删除当前数据吗？', function (index) {
                        layer.close(index);
                        $.ajax({
                            url: serverPath.systemPath + setter.sysLinkPath + "fileManagement/deleteFile",
                            type: "post",
                            dataType: 'json',
                            data: {fileIds: obj.data.id},
                            success: function (res) {
                                layer.alert(res.msg);
                                if(res.code=='0'){
                                    table.reload('fileManagementList', {
                                        page: {curr: 1, limit: 10},
                                    });
                                    totalFilter.init('fileManagementList');
                                    var treeNodeNow= $.fn.zTree.getZTreeObj("treeSelectRoles");
                                    var delNodeInfo=treeNodeNow.getNodesByParam("id",obj.data.id )[0];
                                    treeNodeNow.removeNode(delNodeInfo);
                                    if(obj.data.id ==globalVriable.nowTreeNodeid){
                                        globalVriable.nowTreeNodeinfo='';
                                        globalVriable.nowTreeNodeid='';
                                    }
                                }
                            }
                        })
                    });
                    break;
                case 'edit':
                    if(obj.data.fileType=='1'){
                        events.editFile('1',obj)
                    }else{
                        layer.open({
                            type: 2,
                            area:(globalVriable.parentType=='1'? ['560px', '550px']:['560px', '660px']),
                            title: ['文件修改'],
                            content:  serverPath.systemPath + setter.sysLinkPath + 'fileManagement/view/edit?fileId='+obj.data.id,
                            btn: ['保存','取消'],
                            yes:function (index, layero) {
                                var iframeWindow = window['layui-layer-iframe'+ index]
                                    ,submit = layero.find('iframe').contents().find("#fileManagement-edit-form-submit");

                                //监听提交
                                iframeWindow.layui.form.on('submit(fileManagement-edit-form-submit)', function(datas){
                                    datas.field.id=obj.data.id;
                                    $.ajax({
                                        url:serverPath.systemPath + setter.sysLinkPath + "fileManagement/editFile",
                                        type: "post",
                                        contentType: 'application/json',
                                        dataType: 'json',
                                        data:JSON.stringify(datas.field),
                                        success: function (res) {
                                            layer.alert(res.msg,{closeBtn: 0},function (index1) {
                                                layer.close(index1);
                                                if(res.code==0){
                                                    table.reload('fileManagementList', {
                                                        page: {curr: 1, limit: 10},
                                                    });
                                                    totalFilter.init('fileManagementList');
                                                    layer.close(index); //关闭弹层
                                                }
                                            })
                                        }
                                    });
                                });
                                submit.trigger('click');
                            }
                        });
                    }
                    break;
                case 'downloadfile':
                    layer.confirm('确定下载吗？', {}, function (index) {
                        layer.close(index);
                        var url = serverPath.systemPath + setter.sysLinkPath + 'fileManagement/downloadFile?fileIds='+obj.data.id;
                        window.location.href = url;
                    });
                    break;
                case 'fileName':
                    if (data.fileType==2){
                        return
                    }else {
                        var zTreeMenu = $.fn.zTree.getZTreeObj("treeSelectRoles");
                        var node=zTreeMenu.getNodeByParam('id',data.id);
                        if (node){//判断有查询到节点
                            zTreeMenu.selectNode(node);//选中指定节点
                        }
                        globalVriable.nowTreeNodeid = node.id;
                        globalVriable.nowTreeNodeinfo = node;//当前节点信息
                        common.tableConditionRender("fileManagementList", "fileSelect", {where: {"parentId": data.id,parentType:data.parentType}}, true);
                    }
                    break;
            }
        });
        common.tableSort('fileManagementList');

        var events={
            ztreeNodeData:''//根节点和新建文件夹请求数据

            ,zTreeRefresh:function () {//刷新树
                fileZtree({treeType:globalVriable.parentType});
            }

            ,zTreeshow:function () {//展开树
                $.fn.zTree.getZTreeObj("treeSelectRoles").expandAll(true);
            }

            ,zTreeClose:function () {//收起树
                $.fn.zTree.getZTreeObj("treeSelectRoles").expandAll(false);
            }

            ,ztreeReturnData:function (datajson) {//初始树数据
                $.ajax({
                    url:serverPath.systemPath + setter.sysLinkPath + "fileManagement/folder",
                    type: "get",
                    contentType: 'application/json',
                    dataType: 'json',
                    async:false,
                    data:datajson,
                    success: function (data) {
                        if(data.code==0){
                            events.ztreeNodeData=data.data;
                        }
                    }
                });
            }

            ,addRoot:function () {//添加根节点
                events.ztreeReturnData({selNodeId:globalVriable.nowTreeNodeid,parentType:globalVriable.parentType,parentId:"0"});
                layer.open({
                    type: 1,
                    area: ['460px', '230px'],
                    title: ['添加根节点'],
                    content: $('.fileManagement-addRoot'),
                    btn: ['保存','取消'],
                    success:function(layero, index){
                        form.on('submit(addRootid-submit)', function(data){
                            data.field.parentId=events.ztreeNodeData.parentId;
                            data.field.fileType=1;
                            $.ajax({
                                url:serverPath.systemPath + setter.sysLinkPath + "fileManagement/addFolder",
                                type: "post",
                                contentType: 'application/json',
                                dataType: 'json',
                                data:JSON.stringify(data.field),
                                success: function (res) {
                                    layer.alert(res.msg,{closeBtn: 0},function (index1) {
                                        layer.close(index1);
                                        if(res.code==0){
                                            layer.close(index); //再执行关闭
                                            if(data.field.parentType==globalVriable.parentType){
                                                var zTree = $.fn.zTree.getZTreeObj("treeSelectRoles");
                                                if(globalVriable.parentType==2){
                                                    zTree.addNodes(null, {id:res.data,name:data.field.fileName,icon:serverPath.systemPath+"/systemStatic/images/tree_folder.gif"});
                                                } else{
                                                    zTree.addNodes(null, {id:res.data,name:data.field.fileName});
                                                }
                                            }
                                        }
                                    })
                                }
                            });
                        });
                    },
                    yes:function (index, layero) {
                        layero.find('#addRootidSubmit').click();
                    },
                    btn2:function (index, layero) {
                        layer.close(index); //再执行关闭
                    }
                    ,end:function () {
                        $('input[name="parentType"].radioNodesel').prop('checked','checked');
                        $('input[name="fileName"].rootfileName').val('');
                        form.render('radio')
                    }
                });
            }

            ,addFolder:function (isRight) {//新建文件夹
                hideRMenu();
                var  nodeInfo='';//当前节点信息
                if(isRight=='1'){//单击树信息
                    events.ztreeReturnData({parentId:globalVriable.nowTreeNodeid});
                    nodeInfo=globalVriable.nowTreeNodeinfo;
                }else{//右键树信息
                    events.ztreeReturnData({parentId:globalVriable.nowRightTreeNodeid});
                    nodeInfo=globalVriable.nowRightTreeNodeinfo;
                }
                if(nodeInfo){
                    layer.open({
                        type: 1,
                        area: ['460px', '230px'],
                        title: ['新建文件夹'],
                        content: $('.fileManagement-addFolder'),
                        btn: ['保存','取消'],
                        success:function(layero, index){
                            layero.find('.parentNamecont').html('');
                            layero.find('.parentNamecont').html(nodeInfo.name);
                            form.on('submit(addFolder-submit)', function(data){
                                data.field.parentId=events.ztreeNodeData.parentId;
                                data.field.parentType=globalVriable.parentType;
                                data.field.fileType=1;
                                $.ajax({
                                    url: serverPath.systemPath + setter.sysLinkPath + "fileManagement/addFolder",
                                    type: "post",
                                    contentType: 'application/json',
                                    dataType: 'json',
                                    data: JSON.stringify(data.field),
                                    success: function (res) {
                                        layer.alert(res.msg, {closeBtn: 0},function (index1) {
                                            layer.close(index1);
                                            if (res.code == 0) {
                                                layer.close(index); //再执行关闭
                                                if(isRight=='1'){//单击树信息
                                                    table.reload('fileManagementList', {
                                                        page: {curr: 1, limit: 10},
                                                    });
                                                    totalFilter.init('fileManagementList');
                                                }else{
                                                    if(globalVriable.nowRightTreeNodeid==globalVriable.nowTreeNodeid){
                                                        table.reload('fileManagementList', {
                                                            page: {curr: 1, limit: 10},
                                                        });
                                                        totalFilter.init('fileManagementList');
                                                    }
                                                }
                                                if (data.field.parentType == globalVriable.parentType) {
                                                    var zTree = $.fn.zTree.getZTreeObj("treeSelectRoles");
                                                    if (globalVriable.parentType == 2) {
                                                        zTree.addNodes(nodeInfo, {
                                                            id: res.data,
                                                            name: data.field.fileName,
                                                            icon: serverPath.systemPath + "/systemStatic/images/tree_folder.gif"
                                                        });
                                                    } else {
                                                        zTree.addNodes(nodeInfo, {
                                                            id: res.data,
                                                            name: data.field.fileName
                                                        });
                                                    }
                                                }
                                            }
                                        })
                                    }
                                });
                            });
                        },
                        yes:function (index, layero) {
                            layero.find('#addFolderSubmit').click();
                        },
                        btn2:function (index, layero) {
                            layer.close(index); //再执行关闭
                        },
                        end:function () {
                            $('input[name="fileName"].addfolderfileName').val('');
                        }
                    });
                }else{
                    layer.alert('请选择节点')
                }
            }

            ,addFiles:function (isRight) {//上传
                hideRMenu();
                var nodeInfo='';
                if(isRight=='1'){//单击树信息
                    nodeInfo=globalVriable.nowTreeNodeinfo;
                }else{//右键树信息
                    nodeInfo=globalVriable.nowRightTreeNodeinfo;
                }
                if(nodeInfo){
                    layer.open({
                        type: 2,
                        area: ['800px', '585px'],
                        title: ['上传文件'],
                        content: serverPath.systemPath + setter.sysLinkPath + 'fileManagement/view/file?parentId='+nodeInfo.id,
                        btn: ['保存', '取消'],
                        skin: 'btn-class addFiles-class',
                        yes: function(index, layero){
                            var iframeWindow = window['layui-layer-iframe'+ index]
                                ,submit = layero.find('iframe').contents().find("#fileManagement-file-form-submit");
                            submit.trigger('click');
                        },
                        end:function(){
                            if(isRight=='1'){//单击树信息
                                table.reload('fileManagementList', {
                                    page: {curr: 1, limit: 10},
                                });
                                totalFilter.init('fileManagementList');
                            }else{
                                if(globalVriable.nowRightTreeNodeid==globalVriable.nowTreeNodeid){
                                    table.reload('fileManagementList', {
                                        page: {curr: 1, limit: 10},
                                    });
                                    totalFilter.init('fileManagementList');
                                }
                            }
                        }
                    });
                }else{
                    layer.alert('请选择节点')
                }
            }

            ,downloadFiles:function () {//下载
                layer.confirm('确定下载吗？', {}, function (index) {
                    layer.close(index);
                    var url = serverPath.systemPath + setter.sysLinkPath + 'fileManagement/downloadFile?fileIds='+globalVriable.nowRightTreeNodeid;
                    window.location.href = url;
                });
            }

            ,delFiles:function () {//删除
                hideRMenu();
                layer.confirm('确定删除当前数据吗？', function () {
                    $.ajax({
                        url: serverPath.systemPath + setter.sysLinkPath + "fileManagement/deleteFolder",
                        type: "post",
                        dataType: 'json',
                        data: {fileIds: globalVriable.nowRightTreeNodeid},
                        success: function (res) {
                            layer.alert(res.msg);
                            if(res.code=='0'){
                                var treeNodeNow= $.fn.zTree.getZTreeObj("treeSelectRoles");
                                treeNodeNow.removeNode( globalVriable.nowRightTreeNodeinfo);
                                if( (globalVriable.nowRightTreeNodeinfo.pId==globalVriable.nowTreeNodeid)||(globalVriable.nowRightTreeNodeid==globalVriable.nowTreeNodeid)){
                                    table.reload('fileManagementList', {
                                        page: {curr: 1, limit: 10},
                                    });
                                    totalFilter.init('fileManagementList');
                                }
                                if(globalVriable.nowRightTreeNodeid==globalVriable.nowTreeNodeid){
                                    globalVriable.nowTreeNodeinfo='';
                                    globalVriable.nowTreeNodeid='';
                                }
                                globalVriable.nowRightTreeNodeinfo='';
                                globalVriable.nowRightTreeNodeid='';
                            }
                        }
                    })
                })
            }

            ,editFile:function (isType,nodedata) {//编辑
                hideRMenu();
                layer.open({
                    type: 1,
                    area: ['460px', '180px'],
                    title: ['编辑文件夹'],
                    content: $('.fileManagement-editFolder'),
                    btn: ['保存','取消'],
                    success:function(layero, index){
                        if(isType=='1'){
                            $('input[name="fileName"].editfolderfileName').val(nodedata.data.fileName);
                        }else{
                            $('input[name="fileName"].editfolderfileName').val(globalVriable.nowRightTreeNodeinfo.name);
                        }
                        form.on('submit(editFolder-submit)', function(data){
                            if(isType=='1'){
                                data.field.id=nodedata.data.id;
                            }else{
                                data.field.id=globalVriable.nowRightTreeNodeid;
                            }
                            $.ajax({
                                url:serverPath.systemPath + setter.sysLinkPath + "fileManagement/editFolder",
                                type: "post",
                                contentType: 'application/json',
                                dataType: 'json',
                                data:JSON.stringify(data.field),
                                success: function (res) {
                                    layer.alert(res.msg,{closeBtn: 0},function (index1) {
                                        layer.close(index1);
                                        if(res.code==0){
                                            var treeNodeNow= $.fn.zTree.getZTreeObj("treeSelectRoles");
                                            if(isType=='1'){
                                                var delNodeInfo=treeNodeNow.getNodesByParam("id",nodedata.data.id)[0];
                                                delNodeInfo.name=data.field.fileName;
                                                treeNodeNow.updateNode(delNodeInfo);
                                                nodedata.update({
                                                    fileName: data.field.fileName
                                                });
                                            }else{
                                                globalVriable.nowRightTreeNodeinfo.name=data.field.fileName;
                                                treeNodeNow.updateNode( globalVriable.nowRightTreeNodeinfo);
                                                if(globalVriable.nowRightTreeNodeid==globalVriable.nowTreeNodeid){
                                                    globalVriable.nowTreeNodeinfo.name=data.field.fileName;
                                                }
                                                if(globalVriable.nowRightTreeNodeinfo.pId==globalVriable.nowTreeNodeid){
                                                    table.reload('fileManagementList', {
                                                        page: {curr: 1, limit: 10},
                                                    });
                                                }
                                            }
                                            layer.close(index); //再执行关闭
                                        }
                                    })
                                }
                            });
                        });
                    },
                    yes:function (index, layero) {
                        layero.find('#editFolderSubmit').click();
                    },
                    // btn2:function (index, layero) {
                    //     layer.close(index); //再执行关闭
                    // },
                    end:function () {
                        $('input[name="fileName"].editfolderfileName').val('');
                    }
                });
            }

            ,addToMenu:function () {//添加为菜单
                hideRMenu();
                layer.open({
                    type: 2,
                    area: ['1000px', '570px'],
                    title: ['添加资源'],
                    content: serverPath.systemPath + setter.sysLinkPath + 'fileManagement/view/nodeList',
                    success:function(layero, index){
                    },
                    end:function () {
                        $('input[name="fileName"].addfolderfileName').val('');
                    }
                });
            }

            ,toggleTree:function (othis) {//切换树
                var treeType=othis.attr('treeType');
                if (treeType == 1) {
                    othis.attr("title", "切换到物理树");
                    othis.attr("treeType", "2");
                    globalVriable.parentType='2';
                    fileZtree({treeType:'2'});
                }
                if (treeType == 2) {
                    othis.attr("title", "切换到逻辑树");
                    othis.attr("treeType", "1");
                    globalVriable.parentType='1';
                    fileZtree({treeType:'1'});
                }
            }
        };

        //时间点击
        $('body').on('click', '*[fileManage-event]', function(e){
            var othis = $(this), methid = othis.attr('fileManage-event');
            events[methid] ? events[methid].call(this, othis, e) : '';
        });
    });
</script>
</body>
</html>
<link rel="stylesheet" href="${ctx}/css/font/iconfontie.css" media="all"/>
<link rel="stylesheet" href="${ctx}/iconfont/iconfont.css"/>